import copy
car=[0,0,0,0]
flag1=[0,1,2,3]
flag2=[0,1,2,3]
flag_car=[0,0,0,0]
person=["Mike", "Ellie", "Rohan", "Fatma"]
color=["red","purple","blue","green"]
rank= [[0 for i in range(4)] for i in range(4)]
h=i=j=k=0
a=b=c=d=0
for h in flag1:
    car[0]=h
    flag3=copy.copy(flag1)
    flag3.remove(h)
    for i in flag3:
        if i==1:
            car[1]=i
            flag4=copy.copy(flag3)
            flag4.remove(i)
            for j in flag4:
                if j!=3:
                    car[2]=j
                    flag5 =copy.copy(flag4)
                    flag5.remove(j)
                    for k in flag5:
                        car[3]=k
                        flag6 =copy.copy(flag5)
                        flag6.remove(k)
                        for a in flag2:
                            if a!=0 and a!=3:
                                rank[0][car[0]] = a
                                flag7 = copy.copy(flag2)
                                flag7.remove(a)
                                for b in flag7:
                                    if b!=0 and b!=3:
                                        rank[1][car[1]] =b
                                        flag8=copy.copy(flag7)
                                        flag8.remove(b)
                                        for c in flag8:
                                            rank[2][car[2]]=c
                                            flag9=copy.copy(flag8)
                                            flag9.remove(c)
                                            for d in flag9:
                                                rank[3][car[3]]=d
                                                for m in range(4):
                                                    if car[m]==0:
                                                        flag_car[0]=m #谁骑红车
                                                    elif car[m]==1:
                                                        flag_car[1]=m #谁骑紫车
                                                    elif car[m]==2:
                                                        flag_car[2]=m #谁骑蓝车
                                                    else:flag_car[3]=m #谁骑绿车
                                                if rank[flag_car[2]][2]<rank[3][car[3]] and rank[flag_car[3]][3]<rank[flag_car[1]][1]:
                                                    for n in range(4):
                                                        print(person[n],'骑了',color[car[n]],'车，排名：',rank[n][car[n]]+1)





